import java.awt.event.MouseEvent;
import java.util.concurrent.ExecutionException;
import javax.swing.JOptionPane;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;

public class TwitterButtonAddUserController extends TwitterButtonController {

	public TwitterButtonAddUserController(String defaultImagePath,
			String rolloverImagePath) {
		super(defaultImagePath, rolloverImagePath);
	}

	@SuppressWarnings("static-access")
	@Override
	public void mouseClicked(MouseEvent e) {
		final Thread thread = new Thread() {
			@Override
			
			public void run() {
				String userName = JOptionPane.showInputDialog(null,
						"Enter person's twitter name", "Follow!",
						JOptionPane.QUESTION_MESSAGE);
				try {
					Twitter twitter = new TwitterFactory().getInstance();
					twitter.showUser(userName);
					TweetPanelView.twitterUser.add(new TwitterUserModel(userName));
					TweetPanelView.twitterUser.get(
							TweetPanelView.twitterUser.size() - 1).setTweetTime();
					try {
						//TweetPanelModel tpm = new TweetPanelModel();
						//tpm.updateTweets();
						TweetPanelModel.updateTweets();
					} catch (ExecutionException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				} catch (TwitterException | InterruptedException te) {
					if (((TwitterException) te).getStatusCode() == 404) {
						JOptionPane.showMessageDialog(null,
								"User does not exist");
					}
				}
			}
		};
		thread.start();
	}

}
